﻿using System;
using System.Linq;
using System.Linq.Expressions;

namespace nMongo
{
    public partial class MongoRepository<T>
    {        
        /// <summary>
        /// Retrieves an object of the current collection, giving specified conditions.
        /// </summary>
        /// <param name="predicate">Expression to evaluate and determines the condition satisfaction.</param>
        public T GetSingle(Expression<Func<T, bool>> predicate)
        {
            T returned = Select(predicate).SingleOrDefault();

            if (returned != null)
            {
                this.AutoDetectPersistencyByObject(MongoPersistencyState.Retrieved, returned);
            }
            return returned;
        }
    }
}
